package utils

import (
	"fmt"
	"time"
)

func GetStringTimeNow23(t time.Time) string {
	sNowString := t.Format("2006-01-02 15:04:05.000000000")
	part1 := sNowString[0:23]
	return part1
}
func GetStringTime19(t time.Time) string {
	sNowString := t.Format("2006-01-02 15:04:05.000000000")
	part1 := sNowString[0:19]
	return part1
}
func GetStringTime10(t time.Time) string {
	sNowString := t.Format("2006-01-02 15:04:05.000000000")
	part1 := sNowString[0:10]
	return part1
}
func GetStringNow() string {
	sNowString := time.Now().Format("2006-01-02 15:04:05.000000000")
	part1 := sNowString[0:23]
	return part1
}

func GetStringToday() string {
	sTodayString := time.Now().Format("2006-01-02")
	partYear := sTodayString[0:4]
	partMonth := sTodayString[5:7]
	partDay := sTodayString[8:10]
	res := fmt.Sprintf("%s%s%s", partYear, partMonth, partDay)
	return res
}

func GetStringThisMonth() string {
	sMonthString := time.Now().Format("2006-01")
	partYear := sMonthString[0:4]
	partMonth := sMonthString[5:7]
	res := fmt.Sprintf("%s%s", partYear, partMonth)
	return res
}

func GetStringNow4FileName() string {
	sNowString := time.Now().Format("2006-01-02 15:04:05.000000000")
	partYear := sNowString[0:4]
	partMonth := sNowString[5:7]
	partDay := sNowString[8:10]
	partHour := sNowString[11:13]
	partMinute := sNowString[14:16]
	partSecond := sNowString[17:19]
	partMilliSecond := sNowString[20:23]
	//part2 := sNowString[15:18]
	//fmt.Printf("partYear is %s,partMonth is %s,partDay is %s,partHour is %s,partMinute is %s,partSecond is %s,msecond is %s,\n", partYear, partMonth, partDay, partHour, partMinute, partSecond, partMilliSecond)
	res := fmt.Sprintf("%s%s%s_%s%s%s%s", partYear, partMonth, partDay, partHour, partMinute, partSecond, partMilliSecond)
	return res
}

// 推断时候是昔时的第几周

func WeekNoByDate(t time.Time) string {
	yearDay := t.YearDay()
	yearFirstDay := t.AddDate(0, 0, -yearDay+1)
	//firstDayInWeek := int(yearFirstDay.Weekday()) -1 //周一到周日
	firstDayInWeek := int(yearFirstDay.Weekday())    //周日到周六
	//本年第一周有几天
	firstWeekDays := 1
	if firstDayInWeek != 0 {
		firstWeekDays = 7 - firstDayInWeek + 1
	}
	var week int
	if yearDay <= firstWeekDays {
		week = 1
	} else {
		week = (yearDay-firstWeekDays)/7 + 2
	}
	return fmt.Sprintf("%04d%03d", t.Year(), week)
}
